/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.format.annotation.DateTimeFormat;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "dosage")
@XmlRootElement
@NamedQueries({									
    @NamedQuery(name = "Dosage.findAll", query = "SELECT d FROM Dosage d"),
    @NamedQuery(name = "Dosage.findByPharmacyIdOrderBy", query = "SELECT d FROM Dosage d WHERE d.pharmacyId.pharmacyId = :pharmacyId order by d.state DESC"),
    @NamedQuery(name = "Dosage.findByPharmacyIdByStateOrderBy", query = "SELECT d FROM Dosage d WHERE d.pharmacyId.pharmacyId = :pharmacyId AND d.state = :state order by d.state DESC"),
    @NamedQuery(name = "Dosage.findByPharmacyIdByState", query = "SELECT d FROM Dosage d WHERE d.pharmacyId.pharmacyId = :pharmacyId AND d.state = :state "),
    @NamedQuery(name = "Dosage.findByDosageId", query = "SELECT d FROM Dosage d WHERE d.dosageId = :dosageId"),
    @NamedQuery(name = "Dosage.findByDate", query = "SELECT d FROM Dosage d WHERE d.date = :date"),
    @NamedQuery(name = "Dosage.findByNumOfPending", query = "SELECT d FROM Dosage d WHERE d.numOfPending = :numOfPending"),
    @NamedQuery(name = "Dosage.findByOrderNumber", query = "SELECT d FROM Dosage d WHERE d.orderNumber = :orderNumber"),
    @NamedQuery(name = "Dosage.findByKey", query = "SELECT d FROM Dosage d WHERE d.key = :key"),
    @NamedQuery(name = "Dosage.findByDeadline", query = "SELECT d FROM Dosage d WHERE d.deadline = :deadline"),
    @NamedQuery(name = "Dosage.findByStartNumBill", query = "SELECT d FROM Dosage d WHERE d.startNumBill = :startNumBill"),
    @NamedQuery(name = "Dosage.findByEndNumBill", query = "SELECT d FROM Dosage d WHERE d.endNumBill = :endNumBill"),
    @NamedQuery(name = "Dosage.findByLastNumBillIssued", query = "SELECT d FROM Dosage d WHERE d.lastNumBillIssued = :lastNumBillIssued"),
    @NamedQuery(name = "Dosage.findByNit", query = "SELECT d FROM Dosage d WHERE d.nit = :nit"),
    @NamedQuery(name = "Dosage.findByPharmacyIdByStateByCurrentDate", query = "SELECT d FROM Dosage d WHERE d.pharmacyId.pharmacyId = :pharmacyId AND state = :state AND deadline >= CURRENT_DATE"),
    @NamedQuery(name = "Dosage.findByIva", query = "SELECT d FROM Dosage d WHERE d.iva = :iva"),
    @NamedQuery(name = "Dosage.findByIt", query = "SELECT d FROM Dosage d WHERE d.it = :it"),
    @NamedQuery(name = "Dosage.findByState", query = "SELECT d FROM Dosage d WHERE d.state = :state order by d.state DESC")})
public class Dosage implements Serializable {
    private static final long serialVersionUID = 1L;
    /*
    @Id
    @Basic(optional = false)
    @Column(name = "dosageId")*/
    @Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer dosageId;
    @Basic(optional = false)
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Basic(optional = false)
    @Column(name = "numOfPending")
    private BigInteger numOfPending;
    @Basic(optional = false)
    @Column(name = "orderNumber")
    private BigInteger orderNumber;
    @Basic(optional = false)
    @Column(name = "keyDosage")
    private String key;
    @Basic(optional = false)
    @Column(name = "deadline")
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    private Date deadline;
    @Basic(optional = false)
    @Column(name = "startNumBill")
    private int startNumBill;
    @Basic(optional = false)
    @Column(name = "endNumBill")
    private int endNumBill;
    @Basic(optional = false)
    @Column(name = "lastNumBillIssued")
    private int lastNumBillIssued;
    @Basic(optional = false)
    @Column(name = "nit")
    private String nit;
    @Basic(optional = false)
    @Column(name = "iva")
    private double iva;
    @Basic(optional = false)
    @Column(name = "it")
    private double it;
    @Basic(optional = false)
    @Column(name = "state")
    private short state;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dosageId")
    private Collection<Bill> billCollection;
    @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId")
    @ManyToOne
    private Pharmacy pharmacyId;

    public Dosage() {
    }

    public Dosage(Integer dosageId) {
        this.dosageId = dosageId;
    }

    public Dosage(Integer dosageId, Date date, BigInteger numOfPending, BigInteger orderNumber, String key, Date deadline, int startNumBill, int endNumBill, int lastNumBillIssued, String nit, double iva, double it, short state) {
        this.dosageId = dosageId;
        this.date = date;
        this.numOfPending = numOfPending;
        this.orderNumber = orderNumber;
        this.key = key;
        this.deadline = deadline;
        this.startNumBill = startNumBill;
        this.endNumBill = endNumBill;
        this.lastNumBillIssued = lastNumBillIssued;
        this.nit = nit;
        this.iva = iva;
        this.it = it;
        this.state = state;
    }

	public Integer getDosageId() {
        return dosageId;
    }

    public void setDosageId(Integer dosageId) {
        this.dosageId = dosageId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public BigInteger getNumOfPending() {
        return numOfPending;
    }

    public void setNumOfPending(BigInteger numOfPending) {
        this.numOfPending = numOfPending;
    }

    public BigInteger getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(BigInteger orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Date getDeadline() {
        return deadline;
    }

    public void setDeadline(Date deadline) {
        this.deadline = deadline;
    }

    public int getStartNumBill() {
        return startNumBill;
    }

    public void setStartNumBill(int startNumBill) {
        this.startNumBill = startNumBill;
    }

    public int getEndNumBill() {
        return endNumBill;
    }

    public void setEndNumBill(int endNumBill) {
        this.endNumBill = endNumBill;
    }

    public int getLastNumBillIssued() {
        return lastNumBillIssued;
    }

    public void setLastNumBillIssued(int lastNumBillIssued) {
        this.lastNumBillIssued = lastNumBillIssued;
    }

    public String getNit() {
        return nit;
    }

    public void setNit(String nit) {
        this.nit = nit;
    }

    public double getIva() {
        return iva;
    }

    public void setIva(double iva) {
        this.iva = iva;
    }

    public double getIt() {
        return it;
    }

    public void setIt(double it) {
        this.it = it;
    }

    public short getState() {
		return state;
	}

	public void setState(short state) {
		this.state = state;
	}

    @XmlTransient
    public Collection<Bill> getBillCollection() {
        return billCollection;
    }

    public void setBillCollection(Collection<Bill> billCollection) {
        this.billCollection = billCollection;
    }

    public Pharmacy getPharmacyId() {
        return pharmacyId;
    }

    public void setPharmacyId(Pharmacy pharmacyId) {
        this.pharmacyId = pharmacyId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (dosageId != null ? dosageId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Dosage)) {
            return false;
        }
        Dosage other = (Dosage) object;
        if ((this.dosageId == null && other.dosageId != null) || (this.dosageId != null && !this.dosageId.equals(other.dosageId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Dosage[ dosageId=" + dosageId + " ]";
    }
    
}
